﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Profile;

namespace WebSite.cn
{
    public partial class products_category : System.Web.UI.Page
    {
        // Fields
        public string classname = "";
        public string classnames = "";
        public string cname = "";
     
        public string lclassname = "";
        public string lclassnames = "";

        public string SPriceName = "";
        // Methods
        private void Bind()
        {
            DataTable table2;
            this.productsList.PageSize = Convert.ToInt32(info.info1("", "shoppage"));
            if (base.Request.QueryString["typeid"] != null)
            {
                if (base.Request.QueryString["pinid"] != null)
                {
                    this.lclassname = "<li><a href='products_category.aspx?pinid=" + base.Request.QueryString["pinid"] + "'>所有商品</a></li>";
                }
                else
                {
                    this.lclassname = "<li><a href='products_category.aspx'>所有商品</a></li>";
                }
                this.cname = re.webinfo("", re.replace(base.Request.QueryString["typeid"]), "1");
                string str3 = Displaya(re.replace(base.Request.QueryString["typeid"]), "1");
                if (str3.ToString() != "")
                {
                    string[] strArray = str3.ToString().Split(new char[] { '|' });
                    int num = 0;
                    for (int i = strArray.Length - 1; i >= 0; i--)
                    {
                        DataTable table = SQLAccess.GreatDs("select classname,classid from DB_Productclass where classid=" + strArray[i] + "").Tables[0];
                        if (table.Rows.Count > 0)
                        {
                            
                            this.lclassnames = this.lclassnames + "<li>";
                            for (int j = 0; j <= num; j++)
                            {
                                this.lclassnames = this.lclassnames + "&nbsp; ";
                            }
                            if (base.Request.QueryString["pinid"] != null)
                            {
                                string lclassnames = this.lclassnames;
                                this.lclassnames = lclassnames + "<a href='products_category.aspx?typeid=" + table.Rows[0]["classid"].ToString() + "&pinid=" + base.Request.QueryString["pinid"] + "'>" + table.Rows[0]["classname"].ToString() + "</a></li>";
                            }
                            else
                            {
                                string str5 = this.lclassnames;
                                this.lclassnames = str5 + "<a href='products_category.aspx?typeid=" + table.Rows[0]["classid"].ToString() + "'>" + table.Rows[0]["classname"].ToString() + "</a></li>";
                            }
                            if (base.Request.QueryString["typeid"].ToString() == strArray[i].ToString())
                            {
                                this.classnames = this.classnames + " > <span class='text_red03'>" + table.Rows[0]["classname"].ToString() + "</span>";
                            }
                            else if (base.Request.QueryString["pinid"] != null)
                            {
                                string classnames = this.classnames;
                                this.classnames = classnames + " > <a href='products_category.aspx?typeid=" + table.Rows[0]["classid"].ToString() + "&pinid=" + base.Request.QueryString["pinid"] + "'>" + table.Rows[0]["classname"].ToString() + "</a>";
                            }
                            else
                            {
                                string str7 = this.classnames;
                                this.classnames = str7 + " > <a href='products_category.aspx?typeid=" + table.Rows[0]["classid"].ToString() + "'>" + table.Rows[0]["classname"].ToString() + "</a>";
                            }
                        }
                        num++;
                    }
                }
                table2 = SQLAccess.GreatDs("select classname,classid from DB_Productclass where parentid=" + base.Request.QueryString["typeid"] + " and visible=1 order by classorder").Tables[0];
                if (table2.Rows.Count > 0)
                {
                    foreach (DataRow row in table2.Rows)
                    {
                        if (base.Request.QueryString["pinid"] != null)
                        {
                            string str8 = this.lclassnames;
                            this.lclassnames = str8 + "<li> &nbsp; &nbsp; &nbsp; &nbsp;<a href='products_category.aspx?typeid=" + row[1].ToString() + "&pinid=" + base.Request.QueryString["pinid"] + "'>" + row[0].ToString() + "</a></li>";
                        }
                        else
                        {
                            string str9 = this.lclassnames;
                            this.lclassnames = str9 + "<li> &nbsp; &nbsp; &nbsp; &nbsp;<a href='products_category.aspx?typeid=" + row[1].ToString() + "'>" + row[0].ToString() + "</a></li>";
                        }
                    }
                }
            }
            else
            {
                string sql = "select classname,classid from DB_Productclass where parentid=0 and visible=1 order by classorder";
                table2 = SQLAccess.GreatDs(sql).Tables[0];
                if (table2.Rows.Count > 0)
                {
                    foreach (DataRow row2 in table2.Rows)
                    {
                        if (base.Request.QueryString["pinid"] != null)
                        {
                            string str10 = this.lclassnames;
                            this.lclassnames = str10 + "<li> &nbsp; &nbsp;<a href='products_category.aspx?typeid=" + row2[1].ToString() + "&pinid=" + base.Request.QueryString["pinid"] + "'>" + row2[0].ToString() + "</a></li>";
                        }
                        else
                        {
                            string str11 = this.lclassnames;
                            this.lclassnames = str11 + "<li> &nbsp; &nbsp;<a href='products_category.aspx?typeid=" + row2[1].ToString() + "'>" + row2[0].ToString() + "</a></li>";
                        }
                    }
                }
                this.cname = "所有分类";
            }
        }

        public void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                Label label = (Label)e.Item.FindControl("price");
                Label label2 = (Label)e.Item.FindControl("Label1");
                Image image = (Image)e.Item.FindControl("Image1");
                if ((label.Text == "0") || (label.Text == "0.00"))
                {
                    label.Text = label2.Text;
                }
                if (image.ImageUrl.ToString() == "")
                {
                    image.ImageUrl = "../uploadfile/banner/" + info.info1("", "shopmopic");
                }
                else
                {
                    image.ImageUrl = "../uploadfile/product/" + image.ImageUrl.ToString();
                }
            }
        }

        public static string Displaya(string classid, string languages)
        {
            string str2 = "";
            string sql = "select top 1 parentid,classid from DB_Productclass where classid=" + classid + " and languages=" + languages + " order by classorder";
            DataTable table = new DataTable();
            table = SQLAccess.GreatDs(sql).Tables[0];
            if (table.Rows.Count > 0)
            {
                str2 = str2 + table.Rows[0]["classid"].ToString() + "";
                if (table.Rows[0]["parentid"].ToString() != "0")
                {
                    str2 = str2 + "|" + Displaya(table.Rows[0]["parentid"].ToString(), languages);
                }
            }
            return str2.ToString();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                this.Bind();
            }
        }

        protected void PageChanged(object sender, DataGridPageChangedEventArgs e)
        {
            string str2;
            this.productsList.CurrentPageIndex = e.NewPageIndex;
            string sql = "SELECT proid,proname,proprice1,proprice3,proprice4,propic2,typeid, isnull(proisnew3,0) as proisnew3 FROM DB_Shoppro where visible=1 and proisshow=1 and languages=1";
            if (base.Request.QueryString["typeid"] != null)
            {
                str2 = re.returntype(base.Request.QueryString["typeid"], base.Request.QueryString["typeid"], "1");
                sql = sql + " and typeid in(" + str2 + ")";
            }
            if (base.Request.Form["typeid"] != null)
            {
                str2 = re.returntype(base.Request.Form["typeid"], base.Request.Form["typeid"], "1");
                sql = sql + " and typeid in(" + str2 + ")";
            }
            if (base.Request.QueryString["pinid"] != null)
            {
                sql = sql + " and propinpai=" + re.replace(base.Request.QueryString["pinid"]) + "";
            }
            if (base.Request.QueryString["keywords"] != null)
            {
                string str3 = sql;
                sql = str3 + " and (proname like '%" + re.replace(base.Request.QueryString["keywords"]) + "%' or procode like '%" + re.replace(base.Request.QueryString["keywords"]) + "%')";
            }
            sql = sql + " order by proorder";
            DataTable table = new DataTable();
            table = SQLAccess.GreatDs(sql).Tables[0];
            this.productsList.DataSource = table.DefaultView;
            this.productsList.DataBind();
        }

    }

}